package com.gite.nouette.admin.implementation.model;

import com.gite.nouette.admin.contract.model.ICommand;
import com.gite.nouette.admin.contract.model.command.IStateCommandActivation;
import com.gite.nouette.admin.contract.observer.IObservable;
import com.gite.nouette.admin.contract.observer.IObserver;

public abstract class AbstractCommand extends AbstractModel implements ICommand {
	private IStateCommandActivation stateActive;
	private IStateCommandActivation stateDesactive;

	private IStateCommandActivation stateActivation;
	private IObservable<ICommand> observable;

	public AbstractCommand() {
	}

	@Override
	public IStateCommandActivation getStateActive() {
		return this.stateActive;
	}

	@Override
	public void setStateActive(IStateCommandActivation stateActive) {
		this.stateActive = stateActive;
	}

	@Override
	public IStateCommandActivation getStateDesactive() {
		return this.stateDesactive;
	}

	@Override
	public void setStateDesactive(IStateCommandActivation stateDesactive) {
		this.stateDesactive = stateDesactive;
	}

	private IStateCommandActivation getStateActivation() {
		return this.stateActivation;
	}

	private void setStateActivation(IStateCommandActivation stateActivation) {
		this.stateActivation = stateActivation;
	}

	@Override
	public IObservable<ICommand> getObservable() {
		return this.observable;
	}

	@Override
	public void setObservable(IObservable<ICommand> observable) {
		this.observable = observable;
	}

	@Override
	public void execute() {
		getStateActivation().execute();
	}

	@Override
	public boolean isActive() {
		return getStateActivation().isActive();
	}

	@Override
	public void active() {
		setStateActivation(getStateActive());
	}

	@Override
	public void desactive() {
		setStateActivation(getStateDesactive());
	}

	@Override
	public void initActivation(IStateCommandActivation stateCommandActive,
			IStateCommandActivation stateCommandDesactive) {
		setStateActive(stateCommandActive);
		setStateDesactive(stateCommandDesactive);
		active();
	}

	@Override
	public void addObserver(IObserver<ICommand> observer) {
		getObservable().addObserver(observer);
	}

	@Override
	public int countObservers() {
		return getObservable().countObservers();
	}

	@Override
	public void deleteObserver(IObserver<ICommand> observer) {
		getObservable().deleteObserver(observer);
	}

	@Override
	public void notifyObservers() {
		getObservable().notifyObservers();
	}
}
